package com.cn.yz.springboot.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StringResdisController {

	private static Logger logger = LoggerFactory.getLogger(StringResdisController.class);
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Resource(name="stringRedisTemplate")
	private ValueOperations<String,String> valOpsStr;
	
	@RequestMapping("set")
	public String setKeyAndValue(String key, String value){
		logger.debug("访问set:key={},value={}",key,value);  
        valOpsStr.set(key, value);  
        return "Set Ok"; 
	}
	
	@RequestMapping("get")
	public String getKeyAndValue(String key){
		logger.debug("访问get:key={},value={}");  
		stringRedisTemplate.convertAndSend("msg", "1111dd");
        return valOpsStr.get(key);  
	}
	
}
